package com.hnxxxy.workshop.controller;


import com.hnxxxy.workshop.request.WorkshopPageRequest;
import com.hnxxxy.workshop.request.WorkshopRequest;
import com.hnxxxy.workshop.service.WorkshopService;
import com.hnxxxy.workshop.utils.R;
import com.hnxxxy.workshop.vo.WorkshopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 车间 前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/workshop")
@Api(value = "WorkshopController", tags = {"车间模块"})
public class WorkshopController {

    @Resource
    private WorkshopService workshopService;

    @PostMapping("/add")
    @ApiOperation(value = "创建车间")
    public R add(@ApiParam("车间对象") @RequestBody WorkshopRequest workshopRequest){
        workshopService.add(workshopRequest);
        return R.buildSuccess();
    }

    @GetMapping("/remove/{id}")
    @ApiOperation(value = "删除仓库")
    public R deleteById(@ApiParam(value = "车间id",required = true)
                        @PathVariable("id") int id){
        workshopService.deleteById(id);
        return R.buildSuccess();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改车间")
    public R update( @ApiParam("车间对象")
                     @RequestBody WorkshopRequest workshopRequest){
        workshopService.update(workshopRequest);
        return R.buildSuccess();
    }

    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据id查询车间信息")
    public R findByIdWorkshop(@ApiParam(value = "车间id",required = true)
                           @PathVariable("id") int id ){
        WorkshopVO workshopVO = workshopService.findByIdWorkshop(id);
        return R.buildSuccess(workshopVO);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询全部仓库")
    public R findByIdFactory(@ApiParam(value = "分页对象",required = true)
                             @RequestBody WorkshopPageRequest workshopPageRequest){
        Map<String,Object> pageResult = workshopService.page(workshopPageRequest);
        return R.buildSuccess(pageResult);
    }

}

